<?php
class Zendvn_System_Info  {
	//1. Ham khoi tao cua lop
	public function __construct(){
		$this->_key = Zend_Registry::get('keyApp');
		$ns = new Zend_Session_Namespace($this->_key);
		$ns->setExpirationHops(1800);
		
	}
	//2.Tao thông tin của nguoi dang nhap
	public function createInfo(){
		$author = Zend_Auth::getInstance();
		$infoAuthor = $author->getIdentity();
		
		$this->setMemberInfo($infoAuthor);
		$this->setGroupInfo($infoAuthor);
		$this->setAclInfo($infoAuthor);
	}
	public function destroyInfo(){
		$ns = new Zend_Session_Namespace($this->_key);
		$ns->unsetAll();
	}
	public function setMemberInfo($infoAuthor){
		$db = Zend_Registry::get('connectDB');
		$select  = $db->select()
					  ->from('users')
					  ->where('id = ? ',$infoAuthor->id,INTEGER);
		$result  = $db->fetchRow($select);	
		$ns = new Zend_Session_Namespace($this->_key);
		$ns->member = $result;
	}
	public function setGroupInfo($infoAuthor){
		$db = Zend_Registry::get('connectDB');
		//$db = Zend_Db::factory($t,$t1);
		$select = $db->select()
					->from('user_group')
					->where('id = ?',$infoAuthor->group_id,INTEGER);
		$result = $db->fetchRow($select);
		$ns = new Zend_Session_Namespace($this->_key);
		$ns->group = $result;
	}
	public function setAclInfo(){
		$acl = new Zendvn_System_Acl();
		$acl->createPrivilegeArray();
		$acl->createRole();
	}
	public function getMemberInfo($part=null){//$part la 1 array gia tri can lay
		$ns = new Zend_Session_Namespace($this->_key);
		$nsInfo = $ns->getIterator();
		if($part == null){
			$info = $nsInfo['member'];
		}else{
			$info = $nsInfo['member'];
			$info = $info[$part];
		}
		return $info ;
	}
	public function getGroupInfo($part=null){//$part la 1 array gia tri can lay
		$ns = new Zend_Session_Namespace($this->_key);
		$nsInfo = $ns->getIterator();
		if($part == null){
			$info = $nsInfo['group'];
		}else{
			$info = $nsInfo['group'];
			$info = $info[$part];
		}
		return $info ;
	}
	public function getAclInfo($part=null){//$part la 1 array gia tri can lay
		$ns = new Zend_Session_Namespace($this->_key);
		$nsInfo = $ns->getIterator();
		if($part==null){
			$info = $nsInfo['acl'];
		}else {
			$info = $nsInfo['acl'];
			$info = $info[$part];
		}
		return $info;	
	}
}